program udaleniefromend;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement=^element;
  element=record
          value:integer;
          next:pelement;
        end;

procedure add (var head:pelement; num:integer);
  var tmp:pelement;
  begin
    tmp:=head;
    new(head);
    head^.next:=tmp;
    head^.value:=num;
  end;

function DeleteFromTheEndING (var head:pelement; num:integer):integer;
  var
    current : pelement;
  begin
    current:=head;
    if (head<>nil) then begin
      while (current^.next<>nil) do
      begin
        current:=current^.next;
      end;
      DeleteFromTheEndING:=current^.value;
      dispose(current);
      current^.next:=nil;
    end;
  end;

procedure DeleteElement (var head:pelement);
  var
    current, t : pelement;
  begin
    current:=head^.next^.next^.next;
    t:=current^.next^.next;
    dispose(current^.next);
    current:=t.next;
    dispose(t);
  end;

procedure PrintList (head:pelement);
  var
    current:pelement;
  begin
    current:=head;
    while (current<>nil) do
      begin
        writeln(current^.value);
        current:=current^.next;
      end;
    end;





var
  head : pelement;
  n, i, a : integer;
  fin : textfile;

begin
  assignfile(fin, 'input.txt');
  reset(fin);
  readln(fin, n);
  for i:=0 to n-1 do
    begin
      readln(fin,a);
      add(head,a);
    end;
  DeleteElement(head);
  PrintList(head);
  closefile(fin);
  readln;
end.

